package com.avfh.netcard.config;

import com.alibaba.fastjson.serializer.ValueFilter;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class FastJsonValueFilter implements ValueFilter {

    private static final DecimalFormat decimalFormat = new DecimalFormat("0.00");

    @Override
    public Object process(Object object, String name, Object value) {
        if (value == null) {
            return null;
        }

        if (value instanceof Long) {
            return value.toString();
        }

        if (value instanceof BigDecimal || value instanceof Double || value instanceof Float) {
            return decimalFormat.format(value);
        }
        return value;
    }

}
